lawSmallNumbersDialog <- function(){
	if( !require(tcltk) ) stop('This function depends on the tcltk package')
	if(!exists('slider.env')) slider.env<<-new.env()
	n <- 10  ; assign('n',tclVar(n),env=slider.env)
	p <-  0.5; assign('p',tclVar(p),env=slider.env)
	binom.refresh <- function(...){
		n <- as.numeric(evalq(tclvalue(n), env=slider.env))
		p <- as.numeric(evalq(tclvalue(p), env=slider.env))
		mu <- p*n
		sd <- sqrt(n*p*(1-p))
		plot( seq(0,n), dpois( seq(0,n), mu ), type='h', xlim=c(-1,n+1), xlab='x', ylab='Probability', ylim=range(0,dpois( seq(0,n), mu), dbinom(seq(0,n),n,p)))
		points( seq(0,n), dpois( seq(0,n), mu ), pch=16, col='blue')
		points( seq(0,n), dbinom( seq(0,n), n, p), type='h')
		abline(h=0)
		points( seq(0,n), dbinom( seq(0,n), n, p), pch=18, col="red" )
		title( paste("Mean =",round(mu,3),"Std. Dev. =",round(sd,3)))
		legend("topright", c("Binomial", "Poisson"), col = c("red","blue"), pch = c(18,16), merge = TRUE)
	}
	m <- tktoplevel()
	tkwm.title(m,gettext("Law of small numbers", domain="R-RcmdrPlugin.TeachingExtras"))
	tkwm.geometry(m,'+0+0')
	# n
	tkpack(fr <- tkframe(m), side='top')
	tkpack(tklabel(fr, text='n', width='10'), side='right')
	tkpack(sc <- tkscale(fr, command=binom.refresh, from=1, to=100, orient='horiz', resolution=1, showvalue=T), side='left')
	assign('sc',sc,env=slider.env)
	evalq(tkconfigure(sc, variable=n), env=slider.env)
	# p
	tkpack(fr <- tkframe(m), side='top')
	tkpack(tklabel(fr, text='p', width='10'), side='right')
	tkpack(sc <- tkscale(fr, command=binom.refresh, from=0, to=1, orient='horiz', resolution=0.01, showvalue=T), side='left')
	assign('sc',sc,env=slider.env)
	evalq(tkconfigure(sc, variable=p), env=slider.env)
	tkpack(tkbutton(m, text=gettext("Refresh", domain="R-RcmdrPlugin.TeachingExtras"), command=binom.refresh), side='left')
	tkpack(tkbutton(m, text=gettext("Exit", domain="R-RcmdrPlugin.TeachingExtras"), command=function()tkdestroy(m)), side='right')
	
}